import 'dart:convert';

import 'package:http/http.dart' as http;

import 'model/app_upgrade.dart';

const String _baseUrl = 'https://crypts.cn';

// ignore: avoid_classes_with_only_static_members
class AppUpdaterApis {
  static Future<AppUpgrade> upgrade() {
    const String url = '$_baseUrl/appver/app_version.json';
    final Uri uri = Uri.parse(url);
    return http
        .get(uri, headers: {"Content-Type": "text/plain;charset=UTF-8"}).then(
            (http.Response response) {
      if (response.statusCode != 200) {
        throw StateError('statusCode: ${response.statusCode}');
      }
      final Map<String, dynamic> json =
          jsonDecode(response.body) as Map<String, dynamic>;
      print('json  ${response.body}');
      return AppUpgrade.fromJson(json);
    });
  }
}
